package com.yuma.reffunc;

import java.util.Scanner;
import java.util.function.Function;

interface MyUtil<T,U1,U2,R>{
    R deal(T t,U1 u1,U2 u2);
}
interface MyUtil2<T,U1,R>{
    R deal(T t,U1 u1);
}
public class SpecialFunctionRefDemo {
    public static void main(String[] args) {
        // R apply(T t);     特殊方法使用  类名::非静态方法    t.非静态方法()
        Function<String,String> f1 = String::toUpperCase;
        System.out.println(f1.apply("hello"));   // "hello".toUpperCase()

        Function<String,Boolean> f2 = String::isEmpty;
        System.out.println(f2.apply("abc")); //  "abc".isEmpty()

//        Function<Scanner,Integer> f3 = Scanner::nextInt;
//        System.out.println(f3.apply(new Scanner(System.in)));

//        String "".substring(start,end)
        MyUtil<String,Integer,Integer,String> myUtil = String::substring;
        System.out.println(myUtil.deal("hello world",0,5));  // "hello world".subString(0,5)

        MyUtil2<String,Integer,Character> myUtil2 = String::charAt;
        System.out.println(myUtil2.deal("hello world",5));   // "hello world".charAt(5)

        MyUtil2<String,String,Boolean> myUtil3 = String::contains;
        System.out.println(myUtil3.deal("hello world","world"));  // "hello world".contains("world")
    }
}
